<template>
  <div class="img"><img src="../../assets/img/doctor.png" alt=""></div>
  <div class="login">
    <h3>欢迎登录</h3>
    <el-form :model="user" label-width="60px">
      <el-form-item label="用户名">
        <el-input v-model="user.username" placeholder="请输入手机号码" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" show-password v-model="user.password" placeholder="请输入密码" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin">登录</el-button>
      </el-form-item>
    </el-form>
    <p>忘记密码请联系管理员</p>
  </div>
</template>

<script>
import { ElMessage } from 'element-plus'
export default {
  name: 'Login',
  data() {
    return {
      user: {
        username: 'admin',
        password: 'admin',
      },
    }
  },
  methods: {
    async handleLogin() {
      const loginResult = await this.$store.dispatch('loginAction', this.user)
      if (loginResult) { 
        this.$router.push('/')
      } else { 
        ElMessage.error('用户名或密码错误!')
      }

    },
  },
}
</script>

<style scoped>
  .login {
    width: 300px;
    height: 300px;
    /* border: 1px solid #ccc; */
    padding: 12px;
    top: 170px;
    /* bottom: 0; */
    /* left: 0; */
    right: 200px;
    /* margin: auto; */
    position: absolute;

    /* display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center; */
  }
  .login h3 {
    font-size: 30px;
  }
  .login p {
    font-size: 14px;
    color: #888;
  }
  .img {
    left: 100px;
    top:10px;
    position: absolute;
  }
</style>
